package com.glaway.car.controller;

import com.glaway.car.Service.AdminService;
import com.glaway.car.entity.Admin;
import com.glaway.car.result.Result;
import com.glaway.car.vo.LoginVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    private AdminService adminService;
    private static final Logger log = LoggerFactory.getLogger(LoginController.class);

    /**
     * 登录
     * @param admin admin
     * @return Result
     */
    @PostMapping("/login")
    public Result login(@RequestBody Admin admin){
        log.info("登录，loginParam={}", admin);
        LoginVO loginVO = adminService.login(admin);
        if(loginVO != null){
            return Result.success(loginVO);
        }
        return Result.error("用户名或密码错误");
    }
}
